<!--
 * @Author: HeAo
 * @Date: 2021-12-22 16:33:02
 * @LastEditTime: 2022-01-06 17:03:06
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \am-ui\src\pages\am\monitor\PointInfo.vue
 * 别乱动！
-->
<!--<template>
  <div class="engineer">检测点信息</div>
</template>-->
<template>
  <div class="history">
    <div class="content">
      <div class="left">
        <el-input
          placeholder="请输入设备关键字"
          v-model="filterText"
          style="width: 70%; margin-top: 10px; margin-bottom: 10px"
        ></el-input>
        <el-tree
          class="filter-tree"
          :data="edTree"
          :props="props"
          @node-click="handleNodeClick"
          :filter-node-method="filterNode"
          ref="tree"
        >
        </el-tree>
      </div>
      <div class="right">
        <!-- {{ device }} -->
        <div>
          <el-col :span="18">
            <div v-if="params.device_id">
              <el-form label-width="150px">
                <el-row>
                  <h3>工程详情</h3>
                  <el-col :span="12">
                    <el-form-item label="工程名称:">
                      {{ device.engineer.name }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工程编号:">
                      {{ device.engineer.serial_number }}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="工程类型:"
                      >{{ device.engineer.type }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工程状态:">
                      <el-tag type="danger">{{
                        device.engineer.status
                      }}</el-tag>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="开始时间:">
                      {{ device.engineer.begin_time | fmtTime }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="结束时间:">
                      {{ device.engineer.end_time | fmtTime }}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="工程地址:">
                      {{ device.engineer.address }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工程负责人:">
                      {{ device.engineer.charge_id }}</el-form-item
                    >
                  </el-col>
                </el-row>
              </el-form>

              <div class="device">
                <h3>设备信息</h3>
                <el-form label-width="150px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="设备名称:">
                        {{ device.name }}
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="设备编号:">
                        {{ device.serial_number }}
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="在线状态:">
                        <template v-slot="scope">
                          <el-tag
                            size="mini"
                            v-if="scope.online_status == 1"
                            type="success"
                            >在线</el-tag
                          >
                          <el-tag size="mini" v-else type="danger">离线</el-tag>
                        </template>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="绑定状态:">
                        <template v-slot="scope">
                          <el-tag
                            size="mini"
                            v-if="scope.bind_status == 1"
                            type="success"
                            >已绑定</el-tag
                          >
                          <el-tag size="mini" v-else type="danger"
                            >未绑定</el-tag
                          >
                        </template>
                      </el-form-item>
                    </el-col>

                    <el-col :span="12">
                      <el-form-item label="设备经度:">
                        {{ device.longitude }}
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="设备纬度:">
                        {{ device.insert_time }}
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
            <div v-else class="action">请选择设备</div>
          </el-col>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { get } from "@/utils/request.js";
export default {
  data() {
    return {
      edTree: [],
      props: {
        label: "name",
        value: "id",
      },
      params: {
        page: 1,
        pageSize: 50,
      },
      filterText: "",
      device: {
        engineer: {},
      },
    };
  },
  watch: {
    //监测输入框内容
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    queryTodayData() {
      // let url = ;
      get("/device/findDeviceDetail", { id: this.params.device_id }).then(
        (res) => {
          this.device = res.data;
        }
      );
    },
    filterNode(value, edTree) {
      // console.log(edTree.name.indexOf(value));
      //value是输入框输入的值
      if (!value) return true;

      //返回名称与输入值相同的edTree
      //indexOf(value)==-1不显示
      return edTree.name.indexOf(value) !== -1;
    },
    //树形节点点击事件
    handleNodeClick(data) {
      // console.log(data);
      //点击工程不查询
      if (data.engineer_id) {
        this.params = {
          ...this.params,
          engineer_id: data.engineer_id,
          device_id: data.id,
        }; // 调用请求数据的方法
        this.queryTodayData();
      }
    },
    //查询工程设备树
    findEngineerDeviceTree() {
      get("/engineer/findEngineerDeviceTree").then((res) => {
        let arr = res.data;
        arr.forEach((element, index) => {
          //遍历arr
          if (element.children.length == 0) {
            //将空的删掉
            delete arr[index];
          }
        });
        // console.log(arr);
        var r = arr.filter((item) => {
          //过滤掉空的
          return item !== null || item !== undefined || item !== ""; // 注：IE9(不包含IE9)以下的版本没有trim()方法
        });
        // console.log(r);
        this.edTree = r;
      });
    },
  },
  mounted() {
    this.findEngineerDeviceTree();
  },
};
</script>
<style scoped>
.content {
  display: flex;
}
.left {
  width: 30%;
  border-right: 1px solid #d9d9d9;
}
.right {
  margin-left: 20px;
  width: 100%;
}
.action {
  height: 500px;
  line-height: 500px;
  text-align: center;
  font-size: 30px;
  color: #999999;
}
h3 {
  height: 42px;
  line-height: 42px;
  background: #ededed;
  color: rgb(100, 99, 99);
  font-size: 18px;
  border-radius: 3px;
  padding-left: 1em;
}
::v-deep .el-icon-caret-right:before {
  content: "\e723";
  font-size: 16px;
}

::v-deep .expanded:before {
  content: "\e722";
  font-size: 16px;
}
.action {
  margin-left: 50px;
  height: 500px;
  line-height: 500px;
  text-align: center;
  font-size: 48px;
  font-family: 微软雅黑;
  font-weight: 900;
  color: #999999;
}
</style>